package com.lib.torment.androidlib.widget.networkview;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lib.torment.androidlib.R;


/**
 * 网络错误的布局
 * Created by Torment on 2016/9/12.
 */
public class ErrorNetWorkView extends BaseNetWorkView {
    public int mIconResId;
    public String mTitle;
    public String mSubTitle;
    public String mErrorButton;
    public View.OnClickListener mEmptyButtonClickListener;

    public ErrorNetWorkView(Context context, View view) {
        super(context, view);
    }

    @Override
    protected View inflaterView(ViewGroup parentView) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_network_error, parentView, false);

        ImageView icon = (ImageView) view.findViewById(R.id.icon);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView subTitle = (TextView) view.findViewById(R.id.sub_title);
        TextView errorButton = (TextView) view.findViewById(R.id.error_button);

        if (mIconResId > 0) {
            icon.setImageResource(mIconResId);
        }

        if (!TextUtils.isEmpty(mTitle)) {
            title.setText(mTitle);
        }

        if (!TextUtils.isEmpty(mSubTitle)) {
            subTitle.setText(mSubTitle);
        }

        if (!TextUtils.isEmpty(mErrorButton)) {
            errorButton.setText(mErrorButton);
        }

        if(mEmptyButtonClickListener != null) {
            errorButton.setOnClickListener(mEmptyButtonClickListener);
        }

        return view;
    }
}
